package ar.edu.uba.fi.jmit.aspecter.parser.parsers;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import ar.edu.uba.fi.jmit.aspecter.core.WeavingInstrumentor;
import ar.edu.uba.fi.jmit.aspecter.core.WeavingInstrumentorFactory;
import ar.edu.uba.fi.jmit.aspecter.core.exception.AspecterException;
import ar.edu.uba.fi.jmit.aspecter.parser.configurations.ConfigurationParse;

public class PluginMonitorParse extends MonitorParse {

	private String type;
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public WeavingInstrumentor closeMonitor(String enviromentSelected) throws ClassNotFoundException {
		Map<String, String> params = new HashMap<String, String>();
		params.put("applicationName", this.applicationName);
		Iterator<ConfigurationParse> iterator = this.configurations.getIterator();
		while(iterator.hasNext()){
			ConfigurationParse conf = iterator.next();
			params.putAll(conf.getMapForPlugin());		
		}
		
		try {
			return WeavingInstrumentorFactory.getInstance().getPluginInstrumentor(this.monitorName,this.type , params, this.priority);
		} catch (AspecterException e) {
			// TODO Arreglar
			e.printStackTrace();
		}
		return null;
	}

}
